package com.cpi.cornpp.futurepurchase.services;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
//import com.cpi.cornpp.customer.services.CustomerServices;
//import com.cpi.cornpp.customer.view.CustomerForecastView;
//import com.cpi.cornpp.customer.view.CustomerView;
import com.cpi.cornpp.customerpurchase.converter.CustomerPurchaseConverter;
import com.cpi.cornpp.customerpurchase.dao.CustomerPurchaseDAO;
import com.cpi.cornpp.customerpurchase.dto.CustomerPurchaseDTO;
import com.cpi.cornpp.customerpurchase.service.CustomerPurchaseService;
import com.cpi.cornpp.customerpurchase.view.CustomerPurchaseView;
import com.cpi.cornpp.futurepurchase.converter.FuturePurchaseConverter;
import com.cpi.cornpp.futurepurchase.dao.CustomerFuturePurchaseDAO;
import com.cpi.cornpp.futurepurchase.dao.FuturePurchaseDAO;
import com.cpi.cornpp.futurepurchase.dto.FuturePurchaseDTO;
import com.cpi.cornpp.futurepurchase.dto.FuturePurchaseSearchCriteriaDTO;
import com.cpi.cornpp.futurepurchase.exception.FuturePurchaseException;
import com.cpi.cornpp.futurepurchase.view.FuturePurchaseByCustomerView;
import com.cpi.cornpp.futurepurchase.view.FuturePurchaseSearchCriteriaView;
import com.cpi.cornpp.futurepurchase.view.FuturePurchaseView;
import com.cpi.cornpp.futuresversions.converter.CustomerFuturePurchaseConverter;
import com.cpi.cornpp.futuresversions.dao.CornFuturesVersionsDAO;
import com.cpi.cornpp.futuresversions.exception.CornFuturesVersionsException;
import com.cpi.cornpp.instructionsforecasts.service.InstructionForecastsService;
import com.cpi.cornpp.instructionspurchases.exception.InstructionPurchaseException;
import com.cpi.cornpp.productpurchase.converter.ProductPurchaseConverter;
import com.cpi.cornpp.productpurchase.dao.ProductPurchaseDAO;
import com.cpi.cornpp.productpurchase.dto.ProductPurchaseDTO;
import com.cpi.cornpp.productpurchase.exception.ProductPurchaseException;
import com.cpi.cornpp.productpurchase.services.ProductPurchaseService;
import com.cpi.cornpp.productpurchase.view.ProductPurchaseView;
import com.cpi.cornpp.purchase.program.dao.PurchaseOrderDAO;
import com.cpi.cornpp.purchase.program.exception.PurchaseProgramException;
import com.cpi.cornpp.purchaseinstructiondetail.exception.InstructionPurchaseDetailException;
import com.cpi.cornpp.unit.exception.UnitException;
import com.cs.common.utils.StringUtils;

public class FuturePurchaseService {
	private static final String MSG_NO_INSERT = "The record can not be inserted in the data base.";//$NON-NLS-1$
	//private static final String CON_UNIT = "CON_UNIT";//$NON-NLS-1$
	//private static final String INSTRUCTION_PURCHASE_DETAIL_STATUS_CLOSED_ID = "INSTRUCTION_PURCHASE_DETAIL_STATUS_CLOSED_ID";//$NON-NLS-1$
	//private static final String INSTRUCTION_PURCHASE_STATUS_OPENED_ID = "INSTRUCTION_PURCHASE_STATUS_OPENED_ID";//$NON-NLS-1$
	//private static final String INSTRUCTION_PURCHASE_STATUS_CLOSED_ID = "INSTRUCTION_PURCHASE_STATUS_CLOSED_ID";//$NON-NLS-1$
	private String RELATED_TO_VERSIONS = "label.future.related.to.versions";//$NON-NLS-1$
	private String RELATED_PURCHASES_ORDERS = "label.future.related.to.purchases.orders";//$NON-NLS-1$

	/**
	 * 
	 * @param view
	 * @return
	 * @throws FuturePurchaseException
	 */
	public int insertFuturePurchase(FuturePurchaseView view)
			throws FuturePurchaseException {
		FuturePurchaseDAO fpDAO = null;
		FuturePurchaseDTO dto = null;

		CustomerPurchaseDAO cpDAO = null;
		CustomerPurchaseDTO cpDTO = null;

		List cpViews = null;

		ProductPurchaseDAO ppDAO = null;
		ProductPurchaseConverter ppConverter = null;
		List ppDTOs = null;
		FuturePurchaseConverter futurePurchaseConverter = null;

		int lastFPInserted = 0;
		int lastCPInserted = 0;

		try {
			dto = new FuturePurchaseDTO();
			fpDAO = new FuturePurchaseDAO();
			futurePurchaseConverter = new FuturePurchaseConverter();

			// ** Inserto el FuturePurchase
			dto = futurePurchaseConverter.convert(view);
			lastFPInserted = fpDAO.insert(dto);

			if (lastFPInserted == -1) {
				FuturePurchaseException futurePurchaseException = null;
				futurePurchaseException = new FuturePurchaseException(
						MSG_NO_INSERT, CornPPException.LAYER_SERVICE,
						CornPPException.ACTION_INSERT);
				throw futurePurchaseException;
			}

			cpDAO = new CustomerPurchaseDAO();
			cpViews = view.getCustomerPurchases();
			// cpDTOs = cpConverter.convertViews(view.getCustomerPurchases());

			ppConverter = new ProductPurchaseConverter();
			ppDAO = new ProductPurchaseDAO();
			Iterator iterator = cpViews.iterator();
			CustomerPurchaseView cpView = null;
			while (iterator.hasNext()) {
				cpView = (CustomerPurchaseView) iterator.next();
				// ** Inserto los customer purchases del FuturePurchase
				cpDTO = CustomerPurchaseConverter.convert(cpView);
				cpDTO.setCornFutureId(lastFPInserted);
				lastCPInserted = cpDAO.insert(cpDTO);

				if (lastCPInserted == -1) {
					FuturePurchaseException futurePurchaseException = null;
					futurePurchaseException = new FuturePurchaseException(
							MSG_NO_INSERT, CornPPException.LAYER_SERVICE,
							CornPPException.ACTION_INSERT);
					throw futurePurchaseException;
				}

				// ** Inserto los product purchases de cada Customer purchase
				ppDTOs = ppConverter.convertViews(cpView
						.getProductPurchaseViews());
				Iterator iterator2 = ppDTOs.iterator();
				ProductPurchaseDTO ppDTO = null;
				while (iterator2.hasNext()) {
					ppDTO = (ProductPurchaseDTO) iterator2.next();
					ppDTO.setCornFutureDistributionId(lastCPInserted);
					ppDAO.insert(ppDTO);
				}
			}

		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_INSERT);
			throw futurePurchaseException;
		}
		return lastFPInserted;
	}

	/**
	 * 
	 * @param view
	 * @return
	 * @throws FuturePurchaseException
	 */
	public boolean updateFuturePurchase(FuturePurchaseView view)
			throws FuturePurchaseException {
		FuturePurchaseDAO fpDAO = null;
		FuturePurchaseDTO dto = null;

		CustomerPurchaseDAO cpDAO = null;
		List cpDTOs = null;
		CustomerPurchaseDTO cpDTONew = null;

		ProductPurchaseDAO ppDAO = null;
		ProductPurchaseConverter ppConverter = null;
		List ppDTOs = null;
		FuturePurchaseConverter futurePurchaseConverter = null;

		Iterator it1 = null;
		Iterator it2 = null;
		Iterator it3 = null;

		int numUpdated = 0;
		int lastCPInserted = 0;

		try {
			dto = new FuturePurchaseDTO();
			fpDAO = new FuturePurchaseDAO();
			futurePurchaseConverter = new FuturePurchaseConverter();

			// ** Actualizo el FuturePurchase
			dto = futurePurchaseConverter.convert(view);
			numUpdated = fpDAO.update(dto);

			if (numUpdated != 1) {
				FuturePurchaseException futurePurchaseException = null;
				futurePurchaseException = new FuturePurchaseException(
						MSG_NO_INSERT, CornPPException.LAYER_SERVICE,
						CornPPException.ACTION_INSERT);
				throw futurePurchaseException;
			}

			cpDTOs = new ArrayList(0);
			cpDAO = new CustomerPurchaseDAO();
			cpDTOs = CustomerPurchaseConverter.convertViews(view.getDefaultCustomerPurchases());

			ppConverter = new ProductPurchaseConverter();
			ppDAO = new ProductPurchaseDAO();
			it1 = cpDTOs.iterator();
			while (it1.hasNext()) {
				CustomerPurchaseDTO cpDTO = (CustomerPurchaseDTO) it1.next();
				// Borro los ProductPurchases de cada CustomerPurchase
				ppDAO.delete(cpDTO.getCornFutureDistributionId());

				// Borro el CustomerPurchase
				cpDAO.delete(cpDTO.getCornFutureDistributionId());
			}

			it2 = view.getCustomerPurchases().iterator();
			while (it2.hasNext()) {
				CustomerPurchaseView cpView = (CustomerPurchaseView) it2.next();
				if(cpView.isRemoved())
					continue;
				// ** Inserto los customer purchases del FuturePurchase
				cpView.setFutureId(dto.getCornFutureId());
				cpDTONew = CustomerPurchaseConverter.convert(cpView);
				lastCPInserted = cpDAO.insert(cpDTONew);

				if (lastCPInserted == -1) {
					FuturePurchaseException futurePurchaseException = null;
					futurePurchaseException = new FuturePurchaseException(
							MSG_NO_INSERT, CornPPException.LAYER_SERVICE,
							CornPPException.ACTION_INSERT);
					throw futurePurchaseException;
				}

				// ** Inserto los product purchases de cada Customer purchase
				ppDTOs = ppConverter.convertViews(cpView.getProductPurchaseViews());
				it3 = ppDTOs.iterator();
				while (it3.hasNext()) {
					ProductPurchaseDTO ppDTO = (ProductPurchaseDTO) it3.next();
					ppDTO.setCornFutureDistributionId(lastCPInserted);
					ppDAO.insert(ppDTO);
				}

			}

		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_INSERT);
			throw futurePurchaseException;
		}
		return true;
	}

	public List getFuturePurchasesByPeriodYearRange(FuturePurchaseSearchCriteriaView searchCriteriaView, int orderField, boolean ascendingOrder)throws FuturePurchaseException {
		FuturePurchaseDAO futurePurchaseDAO = null;
		FuturePurchaseConverter futurePurchaseConverter = null;
		FuturePurchaseSearchCriteriaDTO futurePurchaseSearchCriteriaDTO = null;
		List futurePurchasesDTO = null;
		List futurePurchasesView = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			futurePurchaseConverter = new FuturePurchaseConverter();
			futurePurchaseSearchCriteriaDTO = new FuturePurchaseSearchCriteriaDTO();
			futurePurchaseSearchCriteriaDTO = futurePurchaseConverter.convert(searchCriteriaView);
			futurePurchasesDTO = futurePurchaseDAO.getFuturePurchasesByPeriodYearRange(futurePurchaseSearchCriteriaDTO, orderField,ascendingOrder);
			futurePurchasesView = (List) FuturePurchaseConverter.convertDTOs(futurePurchasesDTO);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = new FuturePurchaseException(exception, CornPPException.LAYER_DAO,CornPPException.ACTION_LISTS);
			throw futurePurchaseException;
		}
		return futurePurchasesView;
	}

	public List getFuturePurchasesByAvailable(int purchaseOrderId,
			int orderByColumn, boolean ascendingOrder)
			throws FuturePurchaseException {
		FuturePurchaseDAO futurePurchaseDAO = null;
		List futurePurchasesDTO = null;
		List futurePurchasesView = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			futurePurchasesDTO = futurePurchaseDAO
					.getFuturePurchasesByAvailable(purchaseOrderId,
							orderByColumn, ascendingOrder);
			futurePurchasesView = (List) FuturePurchaseConverter
					.convertDTOs(futurePurchasesDTO);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = new FuturePurchaseException(
					exception, CornPPException.LAYER_DAO,
					CornPPException.ACTION_LISTS);
			throw futurePurchaseException;
		}
		return futurePurchasesView;
	}

	public void deleteFuturePurchaseByCustomer(int cornFutureId, int cornFutureDistributionId)throws FuturePurchaseException {
		FuturePurchaseDAO futurePurchaseDAO = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			futurePurchaseDAO.deleteDistribution(cornFutureId, cornFutureDistributionId);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace(System.out);
			futurePurchaseException = new FuturePurchaseException(exception,CornPPException.LAYER_SERVICE, CornPPException.ACTION_DELETE);
			throw futurePurchaseException;
		}
	}

	public void insertFuturePurchaseByCustomer(
			FuturePurchaseByCustomerView futurePurchaseByCustomerView)
			throws FuturePurchaseException {
		FuturePurchaseConverter futurePurchaseConverter = null;
		FuturePurchaseView futurePurchaseView = null;
		futurePurchaseConverter = new FuturePurchaseConverter();
		futurePurchaseView = futurePurchaseConverter
				.convertFutureByClientTOFuture(futurePurchaseByCustomerView);
		insertFuturePurchase(futurePurchaseView);
	}

	public void insertRealizedFuturePurchase(int purchaseInstructionDetailId, double cornContacted, String customerId, List productViews, String userId, List instructionsFuturesViews) throws FuturePurchaseException, UnitException, InstructionPurchaseDetailException, InstructionPurchaseException {
		InstructionForecastsService instructionForecastsService = null;
		List instructionsForecastsViews = null;
		try {
			instructionForecastsService = new InstructionForecastsService();
			instructionsForecastsViews = instructionForecastsService.list(productViews, null, customerId, purchaseInstructionDetailId);
			//TODO Generar la recepcion
			System.out.println("insertRealizedFuturePurchase - " + instructionsForecastsViews);
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace(System.out);
			futurePurchaseException = new FuturePurchaseException(exception,CornPPException.LAYER_SERVICE,CornPPException.ACTION_INSERT);
			throw futurePurchaseException;
		}
	}

	public void updateFuturePurchaseByCustomer(
			FuturePurchaseByCustomerView futurePurchaseByCustomerView)
			throws FuturePurchaseException {
		FuturePurchaseConverter futurePurchaseConverter = null;
		FuturePurchaseView futurePurchaseView = null;
		futurePurchaseConverter = new FuturePurchaseConverter();
		futurePurchaseView = futurePurchaseConverter.convertFutureByClientTOFuture(futurePurchaseByCustomerView);
		updateFuturePurchase(futurePurchaseView);
	}

	public FuturePurchaseByCustomerView getFuturePurchaseCustomerViewById(
			int cornFutureDistributionId) throws FuturePurchaseException {
		FuturePurchaseByCustomerView futurePurchaseByCustomerView = null;
		FuturePurchaseDAO futurePurchaseDAO = null;
		FuturePurchaseDTO futurePurchaseDTO = null;
		CustomerPurchaseService customerPurchaseService = null;
		ProductPurchaseService productPurchaseService = null;
		ProductPurchaseView productPurchaseView = null;
		List productPurchaseViews = null;
		List customerPurchaseViews = null;
		FuturePurchaseConverter futurePurchaseConverter = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			customerPurchaseService = new CustomerPurchaseService();
			futurePurchaseConverter = new FuturePurchaseConverter();
			productPurchaseService = new ProductPurchaseService();
			productPurchaseView = new ProductPurchaseView();

			futurePurchaseDTO = futurePurchaseDAO
					.getFuturePurchaseByDistributionId(cornFutureDistributionId);
			customerPurchaseViews = customerPurchaseService
					.getCustomerPurchasesByDistribution(cornFutureDistributionId);
			productPurchaseView
					.setCornFutureDistributionId(cornFutureDistributionId);
			productPurchaseViews = productPurchaseService
					.getProductPurchaseList(productPurchaseView);

			futurePurchaseByCustomerView = futurePurchaseConverter.convert(
					futurePurchaseDTO, customerPurchaseViews,
					productPurchaseViews);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_SELECT);
			throw futurePurchaseException;
		}
		return futurePurchaseByCustomerView;
	}

	/**
	 * Metodo que devuelve un FuturePurchase basado en un ID
	 * 
	 * @param id
	 * @return
	 * @throws FuturePurchaseException
	 * @throws ProductPurchaseException
	 */
	public FuturePurchaseView getFuturePurchaseViewById(int id)
			throws FuturePurchaseException, ProductPurchaseException {
		FuturePurchaseDAO dao = null;
		FuturePurchaseDTO dto = null;
		FuturePurchaseView view = null;
		List cpViews = null;
		List ppViews = null;
		CustomerPurchaseService cpService = null;
		ProductPurchaseService ppService = null;
		ProductPurchaseView ppView = null;

		dto = new FuturePurchaseDTO();
		dto.setCornFutureId(id);
		cpService = new CustomerPurchaseService();
		ppService = new ProductPurchaseService();
		ppView = new ProductPurchaseView();
		cpViews = new ArrayList(0);
		dao = new FuturePurchaseDAO();

		Iterator it1 = null;

		try {
			dto = dao.getFuturePurchaseById(dto);
			view = FuturePurchaseConverter.convert(dto);

			cpViews = cpService.getCustomerPurchasesByFuturePurchase(id);
			view.setCustomerPurchases(cpViews);
			view.setDefaultCustomerPurchases(cpViews);
			it1 = cpViews.iterator();
			while (it1.hasNext()) {
				CustomerPurchaseView cpView = (CustomerPurchaseView) it1.next();
				ppViews = new ArrayList(0);
				ppView.setCornFutureDistributionId(cpView
						.getFutureDistributionId());
				ppViews = ppService.getProductPurchaseList(ppView);
				cpView.setProductPurchaseViews(ppViews);
			}

		} catch (FuturePurchaseException exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_INSERT);
			throw futurePurchaseException;
		}

		return view;

	}

	/**
	 * Verifica si un futuro esta relacionado alguna version o a algun customer
	 * purchase
	 * 
	 * @param cornFutureId
	 * @return
	 * @throws FuturePurchaseException
	 */
	public String futurePurchaseRelated(int cornFutureId)
			throws FuturePurchaseException {
		CornFuturesVersionsDAO cornFuturesVersionsDAO = null;
		PurchaseOrderDAO purchaseOrderDAO = null;
		String relatedTo = StringUtils.EMPTY_STRING;
		try {

			// Relacionado a corn_futures_versions
			cornFuturesVersionsDAO = new CornFuturesVersionsDAO();
			if (cornFuturesVersionsDAO
					.getCornFuturesVersionsByCornFutureId(cornFutureId) != null) {
				relatedTo = RELATED_TO_VERSIONS;
			}

			// Relacionado a ordenes de compra
			purchaseOrderDAO = new PurchaseOrderDAO();
			if (purchaseOrderDAO
					.existPurchaseOrderFutureByCornFutureId(cornFutureId)) {
				relatedTo = RELATED_PURCHASES_ORDERS;
			}

		} catch (CornFuturesVersionsException e) {
			FuturePurchaseException futurePurchaseException = null;
			e.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_DELETE);
			throw futurePurchaseException;
		} catch (PurchaseProgramException e) {
			FuturePurchaseException futurePurchaseException = null;
			e.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_DELETE);
			throw futurePurchaseException;
		}

		return relatedTo;
	}

	/**
	 * Delete future purchase
	 * 
	 * @param futurePurchaseId
	 * @throws FuturePurchaseException
	 */
	public void deleteFuturePurchase(int futurePurchaseId)
			throws FuturePurchaseException {
		FuturePurchaseDAO futurePurchaseDAO = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			futurePurchaseDAO.delete(futurePurchaseId);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = null;
			exception.printStackTrace();
			futurePurchaseException = new FuturePurchaseException(
					futurePurchaseException, CornPPException.LAYER_SERVICE,
					CornPPException.ACTION_DELETE);
			throw futurePurchaseException;
		}
	}

	public List getCustomerFuturePurchasesByCriteria(String product,
			String customer, int beginPeriodYear, int endPeriodYear,
			int orderField, boolean ascendingOrder)
			throws FuturePurchaseException {
		CustomerFuturePurchaseDAO cfpDAO = null;
		List customerFuturePurchasesDTO = null;
		List customerFuturePurchasesView = null;

		cfpDAO = new CustomerFuturePurchaseDAO();

		try {

			customerFuturePurchasesDTO = cfpDAO
					.getCustomerFuturePurchasesByCriteria(product, customer,
							beginPeriodYear, endPeriodYear, orderField,
							ascendingOrder);
			customerFuturePurchasesView = (List) CustomerFuturePurchaseConverter
					.convertDTOList(customerFuturePurchasesDTO);

		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = new FuturePurchaseException(
					exception, CornPPException.LAYER_DAO,
					CornPPException.ACTION_LISTS);
			throw futurePurchaseException;
		}
		return customerFuturePurchasesView;
	}

	/**
	 * Metodo que obtiene un listado de Compras Realizadas
	 * 
	 * @author Edgar Joao
	 * @param id
	 * @param orderField
	 * @param ascendingOrder
	 * @return
	 * @throws FuturePurchaseException
	 */
	public List getFuturePurchasesRealizedList(int id, int orderField,
			boolean ascendingOrder) throws FuturePurchaseException {
		FuturePurchaseDAO futurePurchaseDAO = null;
		List futurePurchasesDTO = null;
		List futurePurchasesView = null;
		try {
			futurePurchaseDAO = new FuturePurchaseDAO();
			futurePurchasesDTO = futurePurchaseDAO.getFuturePurchasesRealized(
					id, orderField, ascendingOrder);
			futurePurchasesView = (List) FuturePurchaseConverter
					.convertDTOs(futurePurchasesDTO);
		} catch (FuturePurchaseException futurePurchaseException) {
			throw futurePurchaseException;
		} catch (Exception exception) {
			FuturePurchaseException futurePurchaseException = new FuturePurchaseException(
					exception, CornPPException.LAYER_DAO,
					CornPPException.ACTION_LISTS);
			throw futurePurchaseException;
		}
		return futurePurchasesView;
	}
}